package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.QuestionDao;
import com.mstore.pojo.Question;

public class QuestionService {

	private QuestionDao questionDao;

	/**
	 * 
	 *查询问题
	 */
	public List<Question> watchQuestions(Question question) {
		List<Question> questions = new ArrayList<Question>();
		List<Object> objects = questionDao.watchQuestions(question);
		for (Object object : objects) {
			Question qu = (Question) object;
			qu.setCreateTime(qu.getCreateTime().substring(0,
					qu.getCreateTime().indexOf(".")));
			questions.add(qu);
		}
		return questions;
	}

	// 保存问题
	public void saveQuestion(Question question) {
		questionDao.saveQuestion(question);
	}

	// 通过id查询问题
	public Question getOneQuestion(Question question) {
		List<Object> objects = questionDao.getOneQuestion(question);
		if (objects == null) {
			return null;
		}
		return (Question) objects.get(0);
	}

	// 修改问题
	public void modifyQuestion(Question question) {
		questionDao.modifyQuestion(question);
	}

	// 删除问题
	public void delQuestion(Question question) {
		questionDao.delQuestion(question);
	}

	// 通过replyId查询问题
	public List<Question> findQuestionsByReplyId(Question question) {
		List<Question> questions = new ArrayList<Question>();
		List<Object> objects = questionDao.findQuestionsByReplyId(question);
		for (Object object : objects) {
			questions.add((Question)object);
		}
		return questions;
	}

	public QuestionDao getQuestionDao() {
		return questionDao;
	}

	public void setQuestionDao(QuestionDao questionDao) {
		this.questionDao = questionDao;
	}

}
